/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cyss.greenball.util;

import com.lianzt.commondata.AbstractCommonData;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 *
 * @author cyss
 */
public class MemoryDataBase {
    public static Map<Integer,AbstractCommonData> GreenBallTable = new ConcurrentHashMap<Integer, AbstractCommonData>();
    
    public static void insertGreenBall(AbstractCommonData greenBall){
        GreenBallTable.put(GreenBallTable.size(), greenBall);
    }
    
    public static AbstractCommonData getGreenBall(Integer id){
        return GreenBallTable.get(id);
    }
    
    public static AbstractCommonData getGreenBall(String key, Object parameter){
        AbstractCommonData acd = null;
        for(Integer id : GreenBallTable.keySet()){
            acd = GreenBallTable.get(id);
            if(parameter instanceof String){
                if(acd.getStringValue(key).equals(parameter)){
                    break;
                }
            } else if(parameter instanceof Float){
                if(acd.getFloatValue(key).equals(parameter)){
                    break;
                }
            } else if(parameter instanceof Integer){
                if(acd.getIntValue(key).equals(parameter)){
                    break;
                }
            }
        }
        return acd;
    }
    
    public static void delGreenBall(Integer id){
        GreenBallTable.remove(id);
    }
}
